<template>

  <div class="common-layout">
    <el-container>
      <el-header>
        <el-menu
          :default-active="activeIndex2"
          class="el-menu-demo"
          mode="horizontal"
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b"
          @select="handleSelect"
        >
          <el-menu-item index="1">Processing Center</el-menu-item>
          <el-sub-menu index="2">
            <template #title>Workspace</template>
            <el-menu-item index="2-1">item one</el-menu-item>
            <el-menu-item index="2-2">item two</el-menu-item>
            <el-menu-item index="2-3">item three</el-menu-item>
            <el-sub-menu index="2-4">
              <template #title>item four</template>
              <el-menu-item index="2-4-1">item one</el-menu-item>
              <el-menu-item index="2-4-2">item two</el-menu-item>
              <el-menu-item index="2-4-3">item three</el-menu-item>
            </el-sub-menu>
          </el-sub-menu>
          <el-menu-item index="3" disabled>Info</el-menu-item>
          <el-menu-item index="4">Orders</el-menu-item>
        </el-menu>
      </el-header>
      <el-container>

        <!-- 左边栏菜单 -->
        <el-aside width="200px">
          <el-menu
              active-text-color="#ffd04b"
              background-color="#545c64"
              class="el-menu-vertical-demo"
              default-active="2"
              text-color="#fff"
              @open="handleOpen"
              @close="handleClose"
              @select="handleLeftSelect"
            >
              <el-sub-menu index="1">
                <template #title>
                  <el-icon><location /></el-icon>
                  <span>系统管理</span>
                </template>
                <el-menu-item index="userlist">用户列表</el-menu-item>
                <el-menu-item index="shopperlist">商户管理</el-menu-item>
                <el-menu-item index="sytemlog">系统日志</el-menu-item>
              </el-sub-menu>

              <el-sub-menu index="3">
                <template #title>
                  <el-icon><location /></el-icon>
                  <span>商品管理</span>
                </template>
                <el-menu-item index="prodlist">商品列表</el-menu-item>
                <el-menu-item index="shopperlist">商品审核</el-menu-item>
              </el-sub-menu>

              <el-sub-menu index="3">
                <template #title>
                  <el-icon><location /></el-icon>
                  <span>订单管理</span>
                </template>
                <el-menu-item index="buycar">购物车</el-menu-item>
                <el-menu-item index="orderlist">订单列表</el-menu-item>
              </el-sub-menu>


              <!-- <el-menu-item index="2">
                <el-icon><icon-menu /></el-icon>
                <span>商家管理</span>
              </el-menu-item>
              <el-menu-item index="3">
                <el-icon><document /></el-icon>
                <span>商品管理</span>
                <el-menu-item index="userlist">商品列表</el-menu-item>

              </el-menu-item>
              <el-menu-item index="4">
                <el-icon><setting /></el-icon>
                <span>订单管理</span>
              </el-menu-item> -->
            </el-menu>
        </el-aside>

        <!-- 右侧主页面 -->
        <el-main>
          <router-view/>
        </el-main>

      </el-container>
    </el-container>
  </div>

</template>

<script setup lang="ts">
import { onMounted, ref } from 'vue';
import {
  Document,
  Menu as IconMenu,
  Location,
  Setting,
} from '@element-plus/icons-vue'
import { useRouter } from 'vue-router';


const router = useRouter();

const activeIndex2 = ref('1')
const handleSelect = (key: string, keyPath: string[]) => {
  console.log(key, keyPath)
}

// 左侧菜单的点击事件
const handleLeftSelect = (key: string, keyPath: string[]) => {
  console.log(key, keyPath);
  if(key == 'userlist') {
    // 显示用户列表
    console.log('显示用户列表');
    router.push('/home/userlist');
  }
  else if(key == 'shopperlist') {
    // 商户列表
    console.log('显示商户列表');

  }
  else if(key == 'sytemlog') {
    // 系统日志
    console.log('显示日志列表');
    router.push('/home/sytemlog');

  }
  else if(key == 'prodlist') {
    // 商品列表
    console.log('显示商品列表');
    router.push('/home/prodlist');
  }
  else if(key == 'buycar') {
    // 商品列表
    console.log('显示购物车');
    router.push('/home/buycar');
  }
  else if(key == 'orderlist') {
    // 商品列表
    console.log('显示订单列表');
    router.push('/home/orderlist');
  }
}

const handleOpen = (key: string, keyPath: string[]) => {
  console.log(key, keyPath)
}
const handleClose = (key: string, keyPath: string[]) => {
  console.log(key, keyPath)
}

// 页面加载钩子函数
onMounted(() => {
  router.push('/home/sailer');
}) 
</script>

<style scoped>

</style>